package test1;

/**
 * @author: hett
 * @date: 2022/1/12 14:28
 */
public class StopThread {

    public static void main(String[] args) {
       Thread thread1= new Thread(()->{
            for (int i = 0; i < 10; i++) {
                if (i == 5){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("Thread1********"+i );
            }
        },"thread1");
       Thread thread2 = new Thread(()->{
           for (int i = 0; i < 10; i++) {
               if (i ==5){
                   try {
                       Thread.sleep(100);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   Thread.interrupted();
               }
               System.out.println("Thread2********" +i);
           }
       },"thread2");
       thread1.start();
       thread2.start();
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(10);
                System.out.println("Thread1的状态******"+thread1.isInterrupted());
                System.out.println("Thread1的状态******"+thread1.getState());
                System.out.println("Thread2的状态******"+thread2.getState());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
